<?php

/**
 * MyHammer IndexedMemcache
 *
 * LICENSE
 *
 * This source file is subject to the GNU General Public License Version 3
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.myhammer.de/opensource/license/gpl.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to opensource@myhammer.de so we can send you a copy immediately.
 *
 * @category   MyHammer
 * @package    IndexedMemcache
 * @subpackage Autoloader
 * @license    http://www.myhammer.de/opensource/license/gpl.txt GNU General Public License Version 3
 * @version    1.0
 * @author     Steven Berg <berg@myhammer.de>
 */

/**
 * load class - autoloader
 *
 * @param string $sClassName
 */
function __autoload($sClassName) {

    // delete first character
    $sClassName = substr($sClassName, 1);
    
    // make next character lower
    $sClassName = strtolower(substr($sClassName, 0, 1)) . substr($sClassName, 1);

    // generate all classpath
    $aPaths = array();
    $aPaths[] = getPathForConfig($sClassName);
    $aPaths[] = getPathForClass('core', $sClassName);
    $aPaths[] = getPathForClass('importer', $sClassName);
    $aPaths[] = getPathForClass('utils', $sClassName);

    foreach ($aPaths as $sPath) {        
        if (fileExist($sPath)) {
            loadClass($sPath);
            break;
        }
    }

}

/**
 * is file exist
 *
 * @param string $sClassPath
 * @return boolean
 */
function fileExist($sClassPath) {
    return file_exists($sClassPath);
}

/**
 * get path for class
 *
 * @param string $sSubFolder
 * @param string $sClassName
 * @return string
 */
function getPathForClass($sSubFolder, $sClassName) {   
    return '../../classes/' . $sSubFolder . '/class.' . $sClassName . '.php';
}

/**
 * get path for configFile
 *
 * @param string $sClassName
 * @return string
 */
function getPathForConfig($sClassName) {
     return '../../init/config.' . $sClassName . '.php';
}

/**
 * require class
 *
 * @param string $sClassPath
 */
function loadClass($sClassPath) {
    require_once $sClassPath;
}